#include "widget.h"
#include <osgQOpenGL/osgQOpenGLWidget>

#include <QBoxLayout>

#include <osgDB/ReadFile>

#include <osgViewer/Viewer>

#include <osgUtil/Optimizer>

#include <osgGA/TrackballManipulator>

#include <QLabel>

Widget::Widget(QWidget *parent)

    : QWidget(parent)

{

  resize(400, 300);
  QHBoxLayout *pLayout = new QHBoxLayout(this);
  pLayout->setMargin(0);
  osgQOpenGLWidget *pOsgW = new osgQOpenGLWidget;
  pLayout->addWidget(pOsgW);

  connect(pOsgW, SIGNAL(initialized()), this, SLOT(initOsg()));
}

Widget::~Widget()

{}

void Widget::initOsg()

{
  osgViewer::Viewer *pViewer = ((osgQOpenGLWidget *)sender())->getOsgViewer();
  pViewer->setCameraManipulator(new osgGA::TrackballManipulator());
  osg::Node *pNode = osgDB::readNodeFile("cow.osg");
  osgUtil::Optimizer optimizer;
  optimizer.optimize(pNode);
  pViewer->setSceneData(pNode);
}
